#pragma once
#include <map>
#include <memory>
#include <mutex>

template <class KEY, class VALUE>
class TsafeMap {
private:
	std::mutex mutex_;
	std::map<KEY, VALUE> connections;
public:
	VALUE getConnect(KEY avKey)
	{
		std::lock_guard<std::mutex> lock(mutex_);
		if (connections.count(avKey) > 0)
		{
			return connections[avKey];
		}
		return VALUE();
	}
	void addConnect(KEY avKey, VALUE avValue)
	{
		std::lock_guard<std::mutex> lock(mutex_);
		connections[avKey] = avValue;
	}
	void delConnect(KEY avKey)
	{
		std::lock_guard<std::mutex> lock(mutex_);
		connections.erase(avKey);
	}
	size_t size() {
		std::lock_guard<std::mutex> lock(mutex_);
		return connections.size();
	}
};

